

var a = getApp(),
  change = null;

Page({
  data: {
    searchClass: "",
    slides: [],//轮播图
    department: [{
      tag: "皮肤科",
      icon: "pifuke color1"
    }, {
      tag: "推拿",
      icon: "tuina color2"
    }, {
      tag: "骨科",
      icon: "guke color3"
    }, {
      tag: "耳鼻咽喉",
      icon: "erbihouke color4"
    }, {
      tag: "检验",
      icon: "jianyan color5"
    }, {
      tag: "B超",
      icon: "Bchaoyuyue-K color6"
    }, {
      tag: "科室7",
      icon: "wrong color7"
    }, {
      tag: "科室8",
      icon: "wrong color8"
    }],
    searchDoctor: [],
    images: [
      { url: "../../images/tagbar/lbt.png" },
      { url: "../../images/yysc4.jpg" },
      { url: "../../images/yysc3.jpg" },
      { url: "../../images/yysc5.jpg" },
      { url: "../../images/yysc6.jpg" },

    ]
  },
  onLoad(options) {
    const slides = [
      { image: 'class="background" mode="widthFix" src="../../images/home_home.png', link: '' },
      { image: 'http://ww1.sinaimg.cn/mw690/006ThXL5ly1fj6ckx9tlwj30u00fqk8n.jpg', link: '/pages/list/list?cat=10' }
    ]
  },
  //预约挂号跳转
  appointgh: function () {
    wx.navigateTo({
      url: '../account/login/login',
    })

  },
  //当日挂号
  datagh: function () {
    wx.navigateTo({
      url: '../account/login/login',
    })
  },
  mydiaglist: function () {
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)

    wx.navigateTo({
      url: '../account/mydiagnosis/mydiagnosis',
    })
  },
  /**
   * 搜索栏聚焦
   */
  searchFocus: function () {
    this.setData({
      searchClass: "inputFocus"
    });
  },
  /**
   * 搜索栏失焦
   */
  searchBlur: function () {
    this.setData({
      searchClass: ""
    })
  },
  /**
   * 搜索关键词
   */
  searchKey: function (e) {

    // 节流算法
    change && clearTimeout(change);

    change = setTimeout(() => {
      change = null;
      let val = e.detail.value;
      val && a.request({
        "doc_name": val,
        "depId": -1,
        "subdepId": -1
      }, "searchDoctor", data => {
        data = data.data;
        if (typeof data == "object") {
          data.map && data.map(res => {
            res.split = res.name.split(val);
            res.key = val;
            return res;
          });
          this.setData({
            searchDoctor: data
          });
        }
      });
    }, 500);
  }
});